package cn.st4rlight.util.page;

import cn.st4rlight.util.exception.BizException;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @author st4rlight <st4rlight@163.com>
 * Created on 2024-05-04
 */
@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel(description = "基础分页请求")
public class PageRequest extends BaseRequest {

    @ApiModelProperty(value = "页码")
    private int pageNo = 1;

    @ApiModelProperty(value = "页大小")
    private int pageSize = 10;


    @ApiModelProperty(hidden = true)
    public int getOffset() {
        int offset = (pageNo - 1) * pageSize;
        if (offset < 0) {
            throw BizException.paramInvalid("非法的分页参数");
        }
        return offset;
    }
}
